package com.easy.service.impl;

import com.easy.annotation.LogMethod;
import com.easy.bean.Brand;
import com.easy.mapper.BrandDao;
import com.easy.service.BrandService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    BrandDao brandDao;

    @LogMethod(serviceName = "品牌添加",recordParam = true,recordReturn = true)
    @Override
    public Brand add(Brand brand) {
        //新增数据
        brandDao.add(brand);
        //通过主键查询数据库中的数据
       Brand result = brandDao.one(brand.getId());
        return result;
    }

   /* //清空缓存
    @CacheEvict(value = "brandCache",key = "#p0",allEntries = true)*/
    @LogMethod(serviceName = "品牌删除",recordParam = true,recordReturn = true)
    @Override
    public int del(Integer id) {
     return   brandDao.del(id);

    }

   /* //更新缓存
    @CachePut(value = "brandCache",key = "#p0.id")*/
    @LogMethod(serviceName = "品牌修改",recordParam = true,recordReturn = true)
    @Override
    public Brand edit(Brand brand) {
        brandDao.edit(brand);
        Brand  result =brandDao.one(brand.getId());
        return result;
    }

    @Override
    public List<Brand> all(Brand brand) {
        return brandDao.all(brand);
    }

    @LogMethod(serviceName = "品牌查询",recordParam = true,recordReturn = true)
    //
   /* @Cacheable(value = "brandCache",key = "#p0")*/
    @Override
    public Brand one(Integer id) {
        return brandDao.one(id);
    }

    @LogMethod(serviceName = "分页查询",recordParam = true,recordReturn = true)
@Override
public void page(Page page, Brand brand) {
        int count =brandDao.pageCount(brand);
        Object data=brandDao.page(brand,page);
        page.setCount(count);
        page.setData(data);
    }
}
